using System.Configuration;
using System.Net;
using NUnit.Extensions.Forms;
using NUnit.Framework;
using TelliTwitter.Lib;

namespace UnitTests.TeleTwitter
{
    public abstract class TestFixtureBase : NUnitFormTest
    {
        public static string Password
        {
            get { return ConfigurationManager.AppSettings["Twitter.Password"]; }
        }

        public static string Username
        {
            get { return ConfigurationManager.AppSettings["Twitter.Username"]; }
        }
        
        public static NetworkCredential GetLoginAsNetworkCredential()
        {
            return new NetworkCredential(Password, Username);
        }
        
        public static void Authenticate()
        {
            TwitterManager.Instance().Username = Username;
            TwitterManager.Instance().Password = Password;
        }
        
        public static void UnAuthenticate()
        {
            TwitterManager.Instance().Username = null;
            TwitterManager.Instance().Password = null;
        }
        
        public static void AssertContains(string actual, params string[] expectedStrings)
        {
            if (expectedStrings.Length > 0)
            {
                foreach (string expectedString in expectedStrings)
                {
                    if (!actual.Contains(expectedString))
                    {
                        Assert.Fail("String does not contain '" + expectedString + "'");
                    }
                }
            }
        }

        public static void AssertNotContains(string actual, params string[] expectedStrings)
        {
            if (expectedStrings.Length > 0)
            {
                foreach (string expectedString in expectedStrings)
                {
                    if (actual.Contains(expectedString))
                    {
                        Assert.Fail("String contains '" + expectedString + "'");
                    }
                }
            }
        }
    }
}
